package org.csu.mypetstore.controller;


import org.csu.mypetstore.domain.Category;
import org.csu.mypetstore.domain.Product;
import org.csu.mypetstore.domain.UserInfo;
import org.csu.mypetstore.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.List;

@Controller
@RequestMapping("/userInfoM")
@SessionAttributes(value = {"account", "order", "cart","userInfo"})
public class UserInfoMController {

      @Autowired
      private UserInfoService userInfoService;

      @GetMapping("/viewUserInfo")
      public String viewUserInfo(Model model) {

            List<UserInfo> userInfoList = userInfoService.getUserInfoList();

            model.addAttribute("userInfoList", userInfoList);

            return "catalog/category";

      }

      @RequestMapping("/updateUserInfo")
      public String modifyUser(  String username, String password, int root,String email, String firstName ,String lastName ,String status ,String address1 ,String address2 ,String city, String state, String zip, String country ,String phone,Model model){

            UserInfo userInfo = new UserInfo(username,password,root,email,firstName,lastName,status,address1,address2,city,state,zip,country,phone);
            userInfoService.updateUserInfo(userInfo);

            List<UserInfo> userInfoList = userInfoService.getUserInfoList();
            model.addAttribute("userInfoList", userInfoList);

            return "managerUser/UserManage" ;//返回查看用户界面

      }



}
